<template>
	<view>
		<view class="log-item" v-for="(v,i) in list" :key="i">
			<view class="between align-c">
				<view class="log-item_name">{{ v.buy.name }}-购买{{ v.type == 1?'课程':(v.type == 2?'商品':'会员卡') }}</view>
				<view class="log-item_num">+{{ v.commission }}</view>
			</view>
			<view class="between align-c log-item_bottom">
				<view class="gray">{{ v.create_at }}</view>
				<view :class="v.status==4?'gray':'red'">{{ v.status == 4?'已入账':'未入账' }}</view>
			</view>
		</view>
		<view v-if="!list || !list.length">
			<image src="/static/none_log.png" mode="widthFix" class="none_log" />
			<text class="noMore">暂无记录</text>
		</view>
		<view class="noMore" v-if="list.length && showNoMore">
			—— 到底啦 ——
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return{
				list: [],
				page: 1,
				last_page: 1,
				showNoMore: false,
			}
		},
		onLoad() {
			this.getList();
		},
		onShow() {
			
		},
		onReachBottom() {
			if(this.page < this.last_page) {
				this.page++;
				this.getList();
			}else {
				this.showNoMore = true;
			}
		},
		methods: {
			async getList() {
				uni.showLoading()
				let res = await this.$api.get('staff/my/detail',{
					page: this.page
				});
				
				if(res.code == 200) {
					uni.hideLoading()
					this.last_page = parseInt(res.data.to)/parseInt(res.data.per_page);
					if(this.page == 1) {
						this.list = res.data.data;
						if(res.data.data.length && res.data.to < res.data.per_page) {
							this.showNoMore = true;
						}
					}else {
						this.list.push(...res.data.data);
					}
				}else {
					uni.hideLoading()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.none_log {
		display: block;
		margin: 0 auto;
		width: 400rpx;
		height: 200rpx;
	}
	.noMore {
		font-size: 24rpx;
		height: 100rpx;
		line-height: 100rpx;
	}
	.noMore {
		font-size: 27rpx;
		color: #BBB;
	}
	.log-item {
		padding: 0 27rpx;
		border-bottom: 1rpx solid #F5F5F5;
		font-size: 24rpx;
		padding-top: 20rpx;
		background-color: #FFF;
		&_bottom {
			padding: 10rpx 0;
		}
		&_name {
			font-size: 27rpx;
		}
		&_num {
			font-weight: bold;
			font-size: 32rpx;
		}
	}
	.log-item:first-child {
		margin-top: 20rpx;
	}
</style>